#Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
import os
import tbe.dsl as tbe
from tbe.common.utils import para_check
from op_gen.template.bscpp.scripts import bscpp_op_compiler

PYF_PATH = os.path.dirname(os.path.realpath(__file__))


def _build_args(x, y):
    inputs = []
    for arg in [x]:
        if arg is not None:
            inputs.append(arg)
    outputs = []
    for arg in [y]:
        if arg is not None:
            outputs.append(arg)
    return inputs, outputs


@para_check.check_op_params(para_check.REQUIRED_INPUT, para_check.REQUIRED_OUTPUT, para_check.KERNEL_NAME)
def relu7(x, y, kernel_name="relu7"):
    inputs, outputs = _build_args(x, y)
    src = os.path.join(PYF_PATH, "relu7.cpp")
    bscpp_op_compiler.compile_op(src, kernel_name, "Relu7", inputs, outputs)
